<?php $this->load->view('layout/header'); ?>

<div class="grid_10" id="content_wrapper">

    <div class="section_wrapper">

        <h3 class="title_black"><?php echo __('invoices'); ?></h3>

        <div class="content toggle no_padding">

            <?php $this->load->view('invoice/search_form'); ?>

            <table style="width: 100%;">
                <tr>
                    <th scope="col" class="first"><?php echo __('id'); ?></th>
                    <th scope="col" ><?php echo __('date'); ?></th>
                    <th scope="col"><?php echo __('customer'); ?></th>
                    <th scope="col" class="col_amount"><?php echo __('amount'); ?></th>
                    <th scope="col" class="last"><?php echo __('actions'); ?></th>
                </tr>

                <?php foreach ($invoices as $invoice): ?>

                    <tr class="hoverall" title="<?php echo __('invoice_note') . ": " . $invoice->note; ?>">
                        
                        <td class="first"><?php echo $invoice->id; ?></td>

                        <td nowrap="nowrap"><?php echo date('Y - m - d',  strtotime($invoice->invoice_date) ) ; ?></td>

                        <td nowrap="nowrap"><?php echo $account[$invoice->account_id]; ?></td>

                        <td class="col_amount"><?php echo format_currency($invoice->amount); ?></td>

                        <td>
                            <a title="<?php echo __('detail'); ?>" href="javascript:void(0);" onclick="submit_invoice(<?php echo $invoice->id; ?>, 'view-invoice-detail');">
                                <?php echo get_icon('detail'); ?>
                            </a>
                            &nbsp;&nbsp;
                            <a href="javascript:void(0);" onclick="submit_invoice(<?php echo $invoice->id; ?>, 'delete');">
                                <?php echo get_icon('delete'); ?>
                            </a>
                        </td>
                    </tr>

                <?php endforeach; ?>


            </table>

            <div id="pagination"><?php echo isset($pagination) ? $pagination : NULL; ?></div>

        </div>       
    </div>

</div>

<!--        edit or delete by submit this form below-->
<?php
echo form_open('', array('id' => 'invoice_list_form'), array('invoice_id' => 0, 'IS_FROM_LIST' => true));
echo form_close();
?>
<!--        edit or delete by submit this form below-->
<script>
    function submit_invoice(id, action)
    {
        $('input[name=invoice_id]').val(id);
        
        if (action=='delete')
            if ( !confirm('<?php echo __('do_you_really_wanna_delete'); ?>'))
        return;
        
        $('#invoice_list_form').attr('action', '/invoice-admin/' + action);
        $('#invoice_list_form').submit();
    }
    
</script>



<?php $this->load->view('layout/footer'); ?>
